<template>
  <!-- 登录页面 -->
  <div class="login-bg">
    <div class="login-container">
      <div class="login-box">
        <!-- 医院Logo区域，带粒子特效和动画 -->
        <div class="logo-area animate-logo">
          <HospitalLogo />
        </div>
        <h2>用户登录</h2>
        <!-- 登录表单区域 -->
        <el-form :model="loginForm" :rules="rules" ref="loginFormRef">
          <el-form-item prop="username">
            <el-input 
              v-model="loginForm.username" 
              placeholder="请输入用户名"
              prefix-icon="el-icon-user"
              @keyup.enter="focusPassword"
              ref="usernameInputRef"
              class="input-ani"
            />
          </el-form-item>
          <el-form-item prop="password">
            <el-input 
              v-model="loginForm.password" 
              type="password" 
              placeholder="请输入密码"
              prefix-icon="el-icon-lock"
              show-password
              @keyup.enter="handleLogin"
              ref="passwordInputRef"
              class="input-ani"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleLogin" class="login-btn">
              登录
            </el-button>
          </el-form-item>
        </el-form>
        <!-- 默认账号密码提示 -->
        <div class="login-tip">账号：123，密码：456</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, nextTick } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import HospitalLogo from '../components/HospitalLogo.vue' // 医院Logo组件

const router = useRouter()
const loginFormRef = ref()
const usernameInputRef = ref()
const passwordInputRef = ref()

// 登录表单数据
const loginForm = reactive({
  username: '',
  password: ''
})

// 登录表单校验规则
const rules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' }
  ]
}

// 回车聚焦密码框
const focusPassword = () => {
  nextTick(() => {
    passwordInputRef.value && passwordInputRef.value.focus && passwordInputRef.value.focus()
  })
}

// 登录处理，账号123密码456
const handleLogin = () => {
  loginFormRef.value.validate((valid) => {
    if (valid) {
      if (loginForm.username === '123' && loginForm.password === '456') {
        // 登录成功，设置登录状态到localStorage
        localStorage.setItem('isLogin', 'true')
        ElMessage.success('登录成功')
        setTimeout(() => {
          router.push('/')
        }, 500)
      } else {
        ElMessage.error('账号或密码错误，账号为123，密码为456')
      }
    }
  })
}
</script>

<style scoped>
/* 背景渐变+粒子动画层次 */
.login-bg {
  min-height: 100vh;
  width: 100vw;
  background: linear-gradient(135deg, #e3f0ff 0%, #f5f7fa 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.login-container {
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-box {
  width: 420px;
  padding: 48px 36px 36px 36px;
  background: rgba(255,255,255,0.98);
  border-radius: 18px;
  box-shadow: 0 8px 32px 0 rgba(80,120,200,0.10), 0 1.5px 8px 0 rgba(80,120,200,0.08);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: box-shadow 0.3s;
}
.login-box:hover {
  box-shadow: 0 12px 40px 0 rgba(80,120,200,0.16), 0 2px 12px 0 rgba(80,120,200,0.10);
}
.logo-area {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 18px;
  height: 90px;
  position: relative;
}
.animate-logo {
  animation: logo-bounce 1.6s cubic-bezier(.68,-0.55,.27,1.55) infinite alternate;
}
@keyframes logo-bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-8px); }
}
.login-box h2 {
  text-align: center;
  margin-bottom: 32px;
  color: #1976d2;
  letter-spacing: 2px;
  font-size: 26px;
  font-weight: 700;
}
.input-ani :deep(.el-input__wrapper) {
  border-radius: 8px;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.input-ani :deep(.el-input__wrapper.is-focus) {
  box-shadow: 0 0 0 2px #90caf9;
  border-color: #1976d2;
}
.login-btn {
  width: 100%;
  height: 44px;
  font-size: 18px;
  border-radius: 8px;
  background: linear-gradient(90deg, #42a5f5 0%, #1976d2 100%);
  border: none;
  box-shadow: 0 2px 8px 0 rgba(33,150,243,0.08);
  font-weight: 600;
  letter-spacing: 1px;
  transition: background 0.2s, box-shadow 0.2s;
}
.login-btn:hover {
  background: linear-gradient(90deg, #1976d2 0%, #42a5f5 100%);
  box-shadow: 0 4px 16px 0 rgba(33,150,243,0.12);
}
.login-tip {
  margin-top: 18px;
  color: #90a4ae;
  text-align: center;
  font-size: 15px;
  letter-spacing: 1px;
}
</style>
